package io.bitmax.exchange.core;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.FrameLayout;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.bitmax.exchange.R;
import io.bitmax.library.mvp.BaseMVPActivity;
import io.bitmax.library.mvp.BasePresenter;
import io.bitmax.library.mvp.IBaseUI;
import io.bitmax.library.utils.LogUtils;

/**
 * Created by gongdongyang on 2018/9/17.
 */

public abstract class BaseActivity<P extends BasePresenter<V>,V extends IBaseUI> extends BaseMVPActivity<P, V>
        implements IBaseUI{

    private int dialogRef;

    protected ProgressDialog dialog;

    protected FrameLayout mContainer;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dialogRef = 0;
        initView();
        addEvent();
    }

    @Override
    protected void initTopView() {
        setContentView(getBaseLayout());
        mContainer = findViewById(R.id.app_container);
        if (getLayout() != 0) {
            getLayoutInflater().inflate(getLayout(), mContainer, true);
        }
    }

    protected int getBaseLayout() {
        return R.layout.app_activity_base;
    }

    @Override
    public void showProgressDialog(String title, String hint) {
        if (!isAlive())
            return;

        dialogRef++;

        if (dialog != null && dialog.isShowing())
            return;

        dialog = ProgressDialog.show(this, title, hint);


    }

    @Override
    public void dismissProgressDialog() {
        if (isAlive() && dialog != null && --dialogRef <= 0)
            dialog.dismiss();
    }

}
